<?php
/**
 * This file is form http://findcat.cn
 *
 * @link     https://findcat.cn
 * @email    1476982312@qq.com
 */
namespace App\Http\Controllers\Home;

use App\Models\Comment;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class CommentController extends Controller
{
    public function userComment(Request $request)
    {
        $request->validate([
            'article_id'     => 'required',
            'comment'        => 'required',
        ], [
            'article_id.required'     => '文章id不能为空',
            'comment.required'        => '评论内容不能为空',
        ]);

        $article = $request->article_id;
        $content = $request->comment;
        $user    = Auth::user();

        return Comment::query()->create([
            'user_id'     => $user->id,
            'articles_id' => $article,
            'content'     => $content,
            'ip'          => '127.0.0.1',
            'status'      => true,
        ]);
    }
}
